using System;
using System.Web.Mail;
using jmail;

namespace OgilvyOne.Utility
{
    public class SendMail
    {
        // Methods
        public static bool SendMailAmex(string fromUser, string fromUserName, string toUser, string toUserName, string subjectNm, string bodyAll)
        {
            try
            {
                MailMessage message = new MailMessage();
                message.BodyFormat = MailFormat.Html;
                message.From = fromUser;
                message.To = toUser;
                message.Subject = subjectNm;
                message.Body = bodyAll;
                message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", "2");
                message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
                message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/urlproxyserver", "182.1.1.200");
                message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/proxyserverport", 80);
                message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "webmaster@amextc.com.cn");
                message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "webmastermail");
                message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout", 5);
                SmtpMail.SmtpServer = "192.168.2.62";
                SmtpMail.Send(message);
            }
            catch (Exception exception)
            {
                throw exception;
            }
            return false;
        }

        public static bool SendMailMichelin(string fromUser, string fromUserName, string toUser, string toUserName, string subjectNm, string bodyAll)
        {
            try
            {
                MailMessage message = new MailMessage();
                message.BodyFormat = MailFormat.Html;
                message.From = fromUser;
                message.To = toUser;
                message.Subject = subjectNm;
                message.Body = bodyAll;
                message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", "2");
                message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
                message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/urlproxyserver", "182.1.1.200");
                message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/proxyserverport", 80);
                message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "ecard@michelin2008.com.cn");
                message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "ecardmail");
                message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout", 5);
                SmtpMail.SmtpServer = "192.168.2.62";
                SmtpMail.Send(message);
            }
            catch (Exception exception)
            {
                throw exception;
            }
            return false;
        }

        public static bool SendMails(string toUser, string toUserName, string fromUser, string fromUserName, string subjectNm, string bodyAll,string ctype)
        {
            bool flag = false;
            try
            {
                MessageClass class2 = new MessageClass();
                class2.Clear();
                class2.ClearRecipients();
                class2.ClearAttachments();
                class2.From = "ecard@vw.com.cn";
                class2.FromName = "VW eCard";
                class2.Charset = "gb2312";  
                class2.AddRecipient(toUser, toUserName, "");
                if (ctype == "1")
                {
                    class2.AddRecipientCC(fromUser, fromUserName, "");            
                }
                class2.Subject = subjectNm;
                class2.HTMLBody = bodyAll;
                class2.MailServerUserName = "ecard@vw.com.cn";
                class2.MailServerPassWord = "volkswagen-ecard";
                flag = class2.Send("127.0.0.1", false);
                class2.Close();
            }
            catch (Exception exception)
            {
                flag = false;
            }
            return flag;
        }

        public static bool SendMailXJP(string fromUser, string fromUserName, string toUser, string toUserName, string subjectNm, string bodyAll)
        {
            try
            {
                MailMessage message = new MailMessage();
                message.BodyFormat = MailFormat.Html;
                message.From = fromUser;
                message.To = toUser;
                message.Subject = subjectNm;
                message.Body = bodyAll;
                message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", "2");
                message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
                message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/urlproxyserver", "182.1.1.200");
                message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/proxyserverport", 80);
                message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "yzhang4");
                message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "Janssen002");
                message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout", 5);
                SmtpMail.SmtpServer = "ncsausygmmea01.ap.jnj.com";
                SmtpMail.Send(message);
            }
            catch (Exception exception)
            {
                throw exception;
            }
            return false;
        }

    }
}
